<template>
    <a-layout id="components-layout-demo-custom-trigger">
        <a-layout-sider
            v-model:collapsed="collapsed"
            :trigger="null"
            collapsible
        >
            <div class="logo" @click="goRouter('/')">学生信息管理系统</div>
            <a-menu
                theme="dark"
                mode="inline"
                v-model:selectedKeys="selectedKeys"
            >
                <a-menu-item key="1" @click="goRouter('/stuList')">
                    <user-outlined />
                    <span>学生信息</span>
                </a-menu-item>
                <a-menu-item key="2" @click="goRouter('/teaList')">
                    <video-camera-outlined />
                    <span>教师信息</span>
                </a-menu-item>
                <a-menu-item key="3" @click="goRouter('/course')">
                    <upload-outlined />
                    <span>课程管理</span>
                </a-menu-item>
            </a-menu>
        </a-layout-sider>
        <a-layout>
            <a-layout-header style="background: #fff; padding: 0">
                <menu-unfold-outlined
                    v-if="collapsed"
                    class="trigger"
                    @click="() => (collapsed = !collapsed)"
                />
                <menu-fold-outlined
                    v-else
                    class="trigger"
                    @click="() => (collapsed = !collapsed)"
                />
                <div class="right-menu">
                    <a-dropdown :trigger="['click']">
                        <a class="ant-dropdown-link" @click.prevent>
                            <a-avatar
                                src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png"
                            />
                        </a>
                        <template #overlay>
                            <a-menu>
                                <router-link to="/home">
                                    <a-menu-item key="1">
                                        {{
                                            $store.state.resourceId.stu_name
                                                ? $store.state.resourceId
                                                      .stu_name
                                                : $store.state.resourceId.t_name
                                        }}
                                    </a-menu-item>
                                </router-link>
                                <a-menu-divider />
                                <a-menu-item key="2" @click="exitLogin">
                                    退出
                                </a-menu-item>
                            </a-menu>
                        </template>
                    </a-dropdown>
                </div>
            </a-layout-header>
            <a-layout-content
                :style="{
                    margin: '24px 16px',
                    padding: '24px',
                    background: '#fff',
                    height: '100%',
                }"
            >
                <router-view></router-view>
            </a-layout-content>
        </a-layout>
    </a-layout>
</template>
<script>
import {
    UserOutlined,
    VideoCameraOutlined,
    UploadOutlined,
    MenuUnfoldOutlined,
    MenuFoldOutlined,
} from "@ant-design/icons-vue";
import { defineComponent, ref } from "vue";
import { useRouter } from "vue-router";
export default defineComponent({
    components: {
        UserOutlined,
        VideoCameraOutlined,
        UploadOutlined,
        MenuUnfoldOutlined,
        MenuFoldOutlined,
    },

    setup() {
        let router = useRouter();
        function goRouter(name) {
            router.push(name);
        }
        function exitLogin() {
            // 退出按钮
            router.replace("/");
        }
        return {
            selectedKeys: ref(["1"]),
            exitLogin,
            collapsed: ref(false),
            goRouter,
        };
    },
});
</script>
<style lang="less" scoped>
*::-webkit-scrollbar {
    display: none;
}
#components-layout-demo-custom-trigger {
    user-select: none;
    height: 100%;
}
#components-layout-demo-custom-trigger .trigger {
    font-size: 18px;
    line-height: 64px;
    padding: 0 24px;
    cursor: pointer;
    transition: color 0.3s;
}

#components-layout-demo-custom-trigger .trigger:hover {
    color: #1890ff;
}

#components-layout-demo-custom-trigger .logo {
    height: 64px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    font-size: 1.3em;
    color: wheat;
}

.site-layout .site-layout-background {
    background: #fff;
}
.right-menu {
    float: right;
    margin-right: 30px;
    height: 100%;
    .ant-dropdown-link {
        display: inline-block;
        padding: 0 10px;
        height: 100%;
        font-size: 18px;
        color: #5a5e66;
        vertical-align: text-bottom;
    }
}
</style>